# @File: cli.py
# -*- coding: utf-8 -*-
# __author:"super"
# @time:2025/7/23 11:52

import click
from click_help_colors import HelpColorsGroup, version_option
from get_define import __version__
from hook_manager import cli_hook
from get_define.handlers import handle_gen_models
from conf.config import NAMING_STRATEGIES


@click.group(cls=HelpColorsGroup,
             invoke_without_command=True,
             help_headers_color='magenta',
             help_options_color='cyan',
             context_settings={"max_content_width": 120, })
@version_option(version=__version__, prog_name="super", message_color="green")
@click.pass_context
def main(ctx):
    # click.echo(__image__)
    if ctx.invoked_subcommand is None:
        click.echo(ctx.get_help())
    cli_hook()


@main.group()
def gen():
    """
    generate api
    """
    pass


@gen.command(name="models")
@click.option("--spec", "-s",
              help="OpenAPI规范文件路径（JSON/YAML/URL）")
@click.option("--output", "-o", help="代码输出目录")
@click.option("--class-name-strategy", "-c",
              type=click.Choice(list(NAMING_STRATEGIES.keys()), case_sensitive=False),
              default="operation_id",
              show_default=True,
              help="API Object Class name生成策略（operation_id/summary/tags）")
@click.option("--custom-strategy", "-cs", required=False,
              help="自定义命名策略的Python模块路径 (例如: 'mypackage.naming.custom_function')")
@click.option("--base-api-class", "-B", default="aomaker.core.api_object.BaseAPIObject",
              show_default=True,
              help="API基类完整路径（module.ClassName格式）")
@click.option("--base-api-class-alias", "-A",
              help="基类在生成代码中的别名")
def gen_models(spec, output, class_name_strategy, custom_strategy, base_api_class, base_api_class_alias):
    """
    Generate Attrs models from an OpenAPI specification.
    """
    handle_gen_models(spec, output, class_name_strategy, custom_strategy, base_api_class, base_api_class_alias)


if __name__ == '__main__':
    main()
